package com.decade.qiyeshapan.entity;

import java.io.Serializable;
import java.util.UUID;

public class Order implements Serializable {
    private String orderId;      // 订单编号
    private String product;      // 产品类型
    private int quantity;        // 数量
    private double unitPrice;   // 单价
    private double totalAmount; // 总金额
    private int paymentTerm;    // 账期（季度数）
    private String isoCertification; // ISO认证要求
    private double cost;        // 成本
    private double profit;       // 利润
    private int year;          // 年份
    private int quarter;       // 季度
    private String region;       // 销售区域

    public Order() {
        this.orderId = "ORD-" + UUID.randomUUID().toString().substring(0, 8).toUpperCase();
    }

    // 全参构造函数
    public Order(String product, int quantity, double unitPrice, 
                int paymentTerm, String isoCertification, double cost,
                int year, int quarter, String region) {
        this();
        this.product = product;
        this.quantity = quantity;
        this.unitPrice = unitPrice;
        this.paymentTerm = paymentTerm;
        this.isoCertification = isoCertification != null ? isoCertification : ""; // 允许空值
        this.cost = cost;
        this.year = year;
        this.quarter = quarter;
        this.region = region;
        updateCalculatedFields();
    }

    // Getter和Setter方法
    public String getOrderId() {
        return orderId;
    }

    public void setOrderId(String orderId) {
        this.orderId = orderId;
    }

    public String getProduct() {
        return product;
    }

    public void setProduct(String product) {
        this.product = product;
    }

    public int getQuantity() {
        return quantity;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
        updateCalculatedFields();
    }

    public double getUnitPrice() {
        return unitPrice;
    }

    public void setUnitPrice(double unitPrice) {
        this.unitPrice = unitPrice;
        updateCalculatedFields();
    }

    public double getTotalAmount() {
        return totalAmount;
    }

    public int getPaymentTerm() {
        return paymentTerm;
    }

    public void setPaymentTerm(int paymentTerm) {
        this.paymentTerm = paymentTerm;
    }

    public String getIsoCertification() {
        return isoCertification;
    }

    public void setIsoCertification(String isoCertification) {
        this.isoCertification = isoCertification;
    }

    public double getCost() {
        return cost;
    }

    public void setCost(double cost) {
        this.cost = cost;
        this.profit = this.totalAmount - cost;
    }

    public double getProfit() {
        return profit;
    }

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public int getQuarter() {
        return quarter;
    }

    public void setQuarter(int quarter) {
        this.quarter = quarter;
    }

    public String getRegion() {
        return region;
    }

    public void setRegion(String region) {
        this.region = region;
    }

    // 自动更新计算字段
    private void updateCalculatedFields() {
        this.totalAmount = this.quantity * this.unitPrice;
        this.profit = this.totalAmount - this.cost;
    }

    @Override
    public String toString() {
        return "Order{" +
                "orderId='" + orderId + '\'' +
                ", product='" + product + '\'' +
                ", region='" + region + '\'' +
                ", quantity=" + quantity +
                ", unitPrice=" + unitPrice +
                ", totalAmount=" + totalAmount +
                ", paymentTerm=" + paymentTerm +
                ", isoCertification='" + isoCertification + '\'' +
                ", cost=" + cost +
                ", profit=" + profit +
                ", year=" + year +
                ", quarter=" + quarter +
                '}';
    }
} 